<?php

namespace app\app\controller;


use app\BaseController;
use app\app\model\ProjectZrrModel;


class ProjectTeamScore extends BaseController
{

    public function list()
    {
        $dw_type = input('dwType', '');
        $city = input('city', '');
        $dw_name = input('dwName', '');
        $project_name = input('projectName', '');
        //$page_size = input('pageSize', '20');


        $where = [];

        //按照分类类型筛选

        if ($dw_type) {
            $where[] = ['a.dw_type', '=', $dw_type];
        }

        if ($project_name) $where[] = ['a.project_name', 'like', '%' . $project_name . '%'];

        if ($dw_name) $where[] = ['a.dw_name', 'like', '%' . $dw_name . '%'];

        $group = ProjectZrrModel::alias('a')
            ->field('a.id,a.project_name,a.dw_name,a.dw_type,a.point,b.id,b.link_project_id,c.project_name as project_main_name,c.id as main_id,c.kg_time as kg_main_time,c.tc_time as tc_main_time')
            ->leftjoin('t_project b', 'a.project_id = b.id')
            ->leftjoin('t_project c', 'b.link_project_id = c.id')
            ->where($where);

        $group_count = $group->count();
        $group_list = $group->select()->toarray();
        $info = $group_list;
        $tmp_arr = array();
        $temp = array();
        foreach ($info as $k => $v) {
            if (!in_array($v['main_id'], $tmp_arr)) {
                $tmp_arr[$k] = $v['main_id'];
                $temp[$k]['id'] = $v['main_id'];
                $temp[$k]['project_name'] = $v['project_main_name'];
                $temp[$k]['kg_time'] = $v['kg_main_time'];
                $temp[$k]['kg_time'] = $v['tc_main_time'];
            }
        }
        foreach ($temp as $key => $value) {
            foreach ($info as $k => $v) {
                if ($value['id'] == $v['link_project_id']) {
                    $temp[$key]['children'][] = $v;
                }
            }
            $group_list = $temp;
        }

        $res = array(
            'total' => $group_count,
            'group_list' => $group_list,
        );
        $this->success('success', $res);
    }


    public function info()
    {
        $id = input('project_id', '');
//        $where[] = ['a.dw_type', 'in', ['劳务分包', '专业分包']];?
        $list = ProjectZrrModel::where('project_id', $id)->select();
        $this->success('success', $list);
    }


}
